"""
演示Python pymysql库的基础操作
"""

from pymysql import Connection

# 构建MySQL数据库的链接
from pymysql.connections import Connection

conn: Connection = Connection(
    host="127.0.0.1",
    port=3306,
    user="root",
    password="123456"
)
# print(conn.get_server_info())

# 执行非查询性质的SQL
# 获取游标对象
cursor = conn.cursor()
# 选择数据库
conn.select_db("test")
# 执行SQL
# cursor.execute("create table test_pymysql(id int)")

# 执行查询性质SQL
cursor.execute("select * from student")

result = cursor.fetchall()
for r in result:
    print(r)

# 关闭链接
conn.close()
